#include "stdafx.h"

#define BOOST_BIND_ENABLE_STDCALL

#include "ScopedAction.h"
#include "boost/bind.hpp"

bool MyHandleClose(HANDLE handle, bool isClose)
{
    if (isClose)
    {
        if (CloseHandle(handle))
        {
            return true;
        }
    }

    return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
    HANDLE fileHandle = CreateFile(L"C:\1", GENERIC_READ|GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, 0, NULL);

    ScopedAction action(boost::bind(&CloseHandle, fileHandle));

    boost::function<bool(bool)> myBoostCloseHandleWithPlaceHolder = boost::bind(&MyHandleClose, fileHandle, _1);
    
    bool isClose = true;
    if (myBoostCloseHandleWithPlaceHolder(isClose))
    {
        std::cout << "Handel is closed";
    }
    else
    {
        std::cout << "Handel isn't closed";
    }

	return 0;
}

